home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / midas060 / samples / midpnt / instlist.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-14  |  7.1 KB  |  264 lines

  1. /*
  2.  *      InstList.cpp
  3.  *
  4.  * MIDAS Module Player for Windows NT Instrument List View
  5.  *
  6.  * $Id: InstList.cpp 1.4 1997/01/14 17:42:08 pekangas Exp $
  7.  *
  8.  * Copyright 1996 Petteri Kangaslampi
  9. */
  10.  
  11. #define WIN32_LEAN_AND_MEAN
  12. #include <string.h>
  13. #include <windows.h>
  14. #include <stdio.h>
  15. #include "midasdll.h"
  16. #include "MidpView.h"
  17. #include "MidpNT.h"
  18. #include "MidpModeless.h"
  19. #include "InstList.h"
  20. #include "MidpRes.h"
  21. #include "ViewList.h"
  22.  
  23.  
  24. LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wparam,
  25.     LPARAM lparam);
  26.  
  27.  
  28.  
  29. InstListView::InstListView(void)
  30. {
  31.     static WNDCLASS wc;
  32.  
  33.     /* Set up and register window class for the view window: */
  34.     wc.style = CS_HREDRAW | CS_VREDRAW;
  35.     wc.lpfnWndProc = WindowProc;
  36.     wc.cbClsExtra = 0;
  37.     wc.cbWndExtra = sizeof(DWORD);
  38.     wc.hInstance = instance;
  39.     wc.hIcon = LoadIcon(instance, "GenericIcon");
  40.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  41.     wc.hbrBackground = NULL;
  42.     wc.lpszMenuName = NULL;
  43.     wc.lpszClassName = "midpInstList";
  44.     if ( RegisterClass(&wc) == 0 )
  45.         Panic("InstListView::InstListView:: RegisterClass() failed");
  46.  
  47.     window = NULL;
  48. }
  49.  
  50.  
  51. InstListView::~InstListView(void)
  52. {
  53.     if ( window != NULL )
  54.     {
  55.         delete window;
  56.         window = NULL;
  57.     }
  58. }
  59.  
  60.  
  61. char *InstListView::Name(void)
  62. {
  63.     return "InstListView";
  64. }
  65.  
  66.  
  67. char *InstListView::Description(void)
  68. {
  69.     return "Instrument List";
  70. }
  71.  
  72.  
  73. midpViewWindow *InstListView::CreateViewWindow(Registry *registry)
  74. {
  75.     if ( window != NULL )
  76.         return (midpViewWindow*) window;
  77.     window = new InstListWindow(0, this, registry);
  78.     return (midpViewWindow*) window;
  79. }
  80.  
  81.  
  82. void InstListView::DestroyViewWindow(midpViewWindow *_window)
  83. {
  84.     if ( _window != window )
  85.         Panic("InstListView::DestroyWindow: _window != window");
  86.  
  87.     delete window;
  88.     window = NULL;
  89. }
  90.  
  91.  
  92.  
  93.  
  94. InstListWindow::InstListWindow(int instanceNumber, midpView *view,
  95.     Registry *registry) :
  96.     midpViewWindow(instanceNumber, view, registry)
  97. {
  98.     HWND        parent = NULL;
  99.  
  100.     if ( viewsChildren )
  101.         parent = mainWinHandle;
  102.  
  103.     instanceNumber = instanceNumber;
  104.  
  105.     hwnd = CreateWindow(
  106.         "midpInstList",                         /* class */
  107.         "Instrument List",                      /* caption */
  108.         WS_POPUPWINDOW | WS_CAPTION | WS_THICKFRAME | WS_VISIBLE,            /* style */
  109. //        100, 100, 400, 200,
  110.         startX,                                 /* init. x pos */
  111.         startY,                                 /* init. y pos */
  112.         startWidth,                             /* init. x size */
  113.         startHeight,                            /* init. y size */
  114. //        mainWinHandle,                          /* parent window */
  115.         parent,
  116.         NULL,                                   /* menu handle */
  117.         instance,                               /* program handle */
  118.         (LPVOID) this                           /* create parms */
  119.     );
  120.  
  121. //    ShowWindow(hwnd, SW_SHOWDEFAULT);
  122. //    UpdateWindow(hwnd);
  123.  
  124.     viewWindowList.AddWindow(this);
  125. }
  126.  
  127.  
  128.  
  129. InstListWindow::~InstListWindow(void)
  130. {
  131.     viewWindowList.RemoveWindow(this);
  132.     DestroyWindow(hwnd);
  133. }
  134.  
  135.  
  136.  
  137. LRESULT CALLBACK InstListWindow::ClassWindowProc(HWND hwnd, UINT message,
  138.     WPARAM wparam, LPARAM lparam)
  139. {
  140.     INT         tabstop = 4;
  141.     hwnd = hwnd;
  142.     wparam = wparam;
  143.     lparam = lparam;
  144.  
  145.     switch ( message )
  146.     {
  147.         case WM_CREATE:
  148.             listWinHandle = CreateWindow(
  149.                 "LISTBOX",
  150.                 NULL,
  151.                 WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL |
  152.                     LBS_USETABSTOPS | LBS_NOINTEGRALHEIGHT,
  153.                 0, 0, 0, 0,             /* set size in WM_SIZE message */
  154.                 hwnd,                   /* parent window */
  155.                 NULL,                   /* edit control ID */
  156.                 instance,
  157.                 NULL);                  /* no window creation data */
  158.  
  159.             SendMessage(listWinHandle, LB_SETHORIZONTALEXTENT, 40, 0);
  160.             SendMessage(listWinHandle, LB_SETTABSTOPS, 1, (LPARAM) &tabstop);
  161.  
  162.             UpdateList();
  163.             return 0;
  164.  
  165.         case WM_SIZE:
  166.             /* Make the list box the size of the window's client area: */
  167.             MoveWindow(listWinHandle,
  168.                 0, 0,           /* starting x- and y-coordinates */
  169.                 LOWORD(lparam), /* width of client area          */
  170.                 HIWORD(lparam), /* height of client area         */
  171.                 TRUE);          /* repaint window                */
  172.                 //SetBkMode
  173.             return 0;
  174.  
  175.         case WM_CLOSE:
  176.             DestroyWindow(listWinHandle);
  177.             ownerView->DestroyViewWindow(this);
  178.             return 0;
  179.  
  180.         case MIDPMSG_SONGCHANGED:
  181.             UpdateList();
  182.             return 0;
  183.  
  184.         default:
  185.             return(DefWindowProc(hwnd, message, wparam, lparam));
  186.     }
  187. }
  188.  
  189.  
  190. void InstListWindow::UpdateList(void)
  191. {
  192.     unsigned    i;
  193.     char        str[128];
  194.     char        name[64];
  195.     HFONT       oldFont, font;
  196.     HDC         hdc;
  197.     SIZE        size;
  198.     int         extent = 0;
  199.     MIDASmoduleInfo moduleInfo;
  200.     MIDASinstrumentInfo instrumentInfo;
  201.  
  202.     font = (HFONT) SendMessage(listWinHandle, WM_GETFONT, 0, 0);
  203.     hdc = GetDC(listWinHandle);
  204.     oldFont = SelectObject(hdc, font);
  205.  
  206.     SendMessage(listWinHandle, LB_RESETCONTENT, 0, 0);
  207.     if ( module != NULL )
  208.     {
  209.         MIDASgetModuleInfo(module, &moduleInfo);
  210.  
  211.         for ( i = 0; i < moduleInfo.numInstruments; i++ )
  212.         {
  213.             MIDASgetInstrumentInfo(module, i, &instrumentInfo);
  214.             OemToChar(instrumentInfo.instName, name);
  215.             sprintf(str, "%02X\t%s", i+1, name);
  216.             SendMessage(listWinHandle, LB_ADDSTRING, 0, (LPARAM) str);
  217.             if ( !GetTextExtentPoint32(hdc, str, strlen(str), &size) )
  218.             {
  219.                 sprintf(str, "ListViewWindow::UpdateList: GetTextExtentPoint"
  220.                     "32 fails (%i)", GetLastError());
  221.                 Panic(str);
  222.             }
  223.             if ( size.cx > extent )
  224.                 extent = size.cx;
  225.         }
  226.     }
  227.  
  228.     SendMessage(listWinHandle, LB_SETHORIZONTALEXTENT, extent, 0);
  229.  
  230.     SelectObject(hdc, oldFont);
  231. }
  232.  
  233.  
  234. static LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wparam,
  235.     LPARAM lparam)
  236. {
  237.     InstListWindow *window;
  238.     LPCREATESTRUCT cs;
  239.  
  240.     if ( message == WM_NCCREATE )
  241.     {
  242.         cs = (LPCREATESTRUCT) lparam;
  243.         window = (InstListWindow*) cs->lpCreateParams;
  244.         SetWindowLong(hwnd, GWL_USERDATA, (LONG) window);
  245.     }
  246.  
  247.     window = (InstListWindow*) GetWindowLong(hwnd, GWL_USERDATA);
  248.  
  249.     return window->ClassWindowProc(hwnd, message, wparam, lparam);
  250. }
  251.  
  252.  
  253. /*
  254.  * $Log: InstList.cpp $
  255.  * Revision 1.4  1997/01/14 17:42:08  pekangas
  256.  * Changed to use MIDAS DLL API
  257.  *
  258.  * Revision 1.3  1996/08/13 20:23:40  pekangas
  259.  * #included stdio.h as MIDAS rawfile.h no longer does that
  260.  *
  261.  * Revision 1.2  1996/07/16  19:25:13  pekangas
  262.  * Removed Visual C warnings, Added RCS keywords, converted to LFs
  263.  *
  264. */